
Panels.Main.ShowCreateMenu = function(object, x, y, id, type)
{
  var info = Utility.ObjectInfo.GetList(object);
  var options = [];
  
  if(object == eStarbase)
  {
    options.push("<option value='npc'>NPC Owned</option>");
    options.push("<option value='player'>Player Owned</option>");
  }
  
  else
  {
    for(var name in info)
    {
      if(!info.hasOwnProperty(name))
        continue;
        
      if(object == eBuilding && info[name].tile & type)
          options.push("<option value='" + name + "'>" + name + "</option>");
          
      else if(object == ePlanet)
        options.push("<option value='" + name + "'>Class " + name + "</option>");
        
      else if(object == eBackground)
        options.push("<option value='" + info[name].image + "'>" + name + "</option>");
    }
  }
  
  options.sort();
  
  var w = "<h2>Create a " + object + (object == eBackground? " Image": "") + "</h2>"
        + Utility.Sector.Name() + " [" + x + ", " + y + "]<br /> <br />"
        + "&nbsp;&nbsp;&nbsp;<select id='createObjectSelect'>" + options.join("") + "</select><br />"
        + (object != eBackground? (object == eBuilding? "Level: ": "Population: ")
        + "<input type='text' id='level' size='" + (object == eBuilding? 2: 7) + "' value='" + (object == eBuilding? Utility.Config.Get("DefaultBuildingLevel"): 500) + "' /><br />": "")
        + (object == eBuilding || object == eStarbase? "Owner: <input type='text' id='owner'><br />": "")
        + "<input type='checkbox' id='useSelectedTiles' />&nbsp;Copy to all selected tiles<br />"
        + "<input type='button' onclick='Panels.Main.Create(\"" + object + "\", " + id + ", " + x + ", " + y + ", " + type
        + ", " + (object == eBackground? "undefined": "$(\"level\").value") + ", $(\"createObjectSelect\").getSelected()[0].value, "
        + ((object == eBuilding || object == eStarbase)? "$(\"owner\").value": "undefined") + ");' value='Create' />"
        + "&nbsp;&nbsp;<input type='button' value='Cancel' onclick='HideMenus();'>";
        
  HideMenus();
  LeftClickMenu.set("html", w);
}

Panels.Main.ShowInfo = function(object, id)
{
  var data = Utility.Object.Get(object, id);
  var info = Utility.ObjectInfo.Get(object, (object == eBuilding ? data.name : (object == ePlanet ? data.type : { type: data.type, npc: data.owner })));

  if (object == eBuilding)
  {
    var name = data.owner + "'s " + data.name;
    var level = data.level;
  }
  else if (object == ePlanet)
  {
    var name = "Class " + data.type + " Planet";
    var level = data.population;
  }
  else if (object == eStarbase)
  {
    var name = (data.npc ? "NPC Starbase" : data.owner + "'s Starbase");
    var level = data.population;
  }
  else
  {
    var name = data.name;
    var level = 0;
  }

  var upkeepHTML = [];
  var productionHTML = [];

  if (object != eBackground)
  {
    var upkeep = data.calculateUpkeep();
    var production = data.calculateProduction();

    for (commodity in upkeep)
    {
      if (!upkeep.hasOwnProperty(commodity))
        continue;

      upkeepHTML.push("<tr class='infoTableColor" + (upkeepHTML.length % 2 == 1 ? 1 : 2) + "'>"
                    + "<td><img src='" + Utility.Config.Get("Imagepack") + "/res/" + Global.Commodities[commodity].image + "'></td>"
                    + "<td>" + commodity + "</td>"
                    + "<td align='right'>" + upkeep[commodity] + "</td>"
                    + "</tr>");
    }

    for (commodity in production)
    {
      if (!production.hasOwnProperty(commodity))
        continue;

      productionHTML.push("<tr class='infoTableColor" + (productionHTML.length % 2 == 1 ? 1 : 2) + "'>"
                        + "<td><img src='" + Utility.Config.Get("Imagepack") + "/res/" + Global.Commodities[commodity].image + "'></td>"
                        + "<td>" + commodity + "</td>"
                        + "<td align='right'>" + production[commodity] + "</td>"
                        + "</tr>");
    }
  }

  var w = "<h3>" + name + "</h3>"
        + Utility.Sector.Name() + " [" + data.x + ", " + data.y + "] <br />";

  if (productionHTML.length > 0)
  {
    w += "Level: <input type='text' id='level' size='" + (object == eBuilding ? 2 : 7) + "' value='" + level + "'"
       + " onblur='Panels.Main.SetLevel(\"" + object + "\", " + id + ", $(\"level\").value);'><br /><br />";
  }

  if (upkeepHTML.length > 0)
  {
    w += "<table><tr><td valign='top'>"
       + "<table class='infoTable' valign='top'><tr><th colspan='3' align='center'>Upkeep</th></tr>"
       + "<tr class='infoTableHeading'><th align='center' colspan='2'>Commodity</th><th align='center'>Amount</th></tr>"
       + upkeepHTML.join("")
       + "</table></td>";

    if (productionHTML.length > 0)
    {
      w += "<td valign='top'><table class='infoTable'><tr><th colspan='3' align='center'>Production</th></tr>"
         + "<tr class='infoTableHeading'><th align='center' colspan='2'>Commodity</th><th align='center'>Amount</th></tr>"
         + productionHTML.join("")
         + "</table></td>";
    }

    w += "</tr></table><br /><br />";
  }
  else
  {
    w += "<br />";
  }

  w += "<input type='button' onclick='HideMenus();' value='Okay' />&nbsp;&nbsp;"
     + "<input type='button' onclick='Panels.Main.DeleteObject(\"" + object + "\", " + id + ");' value='Delete'>";

  HideMenus();
  LeftClickMenu.set("html", w);
}